home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / TCPExample / TCP Libraries / TCPTypes.unit < prev    next >
Encoding:
Text File  |  1992-12-10  |  10.2 KB  |  444 lines  |  [TEXT/PJMM]

  1. unit TCPTypes;
  2.  
  3. { From Peter's PNL Libraries }
  4. { Copyright 1992 Peter N Lewis }
  5. { This source may be used for any non-commercial purposes as long as I get a mention }
  6. { in the About box and Docs of any derivative program.  It may not be used in any commercial }
  7. { application without my permission }
  8.  
  9. interface
  10.  
  11. { MacTCP return Codes in the range -23000 through -23049 }
  12.     const
  13.         inProgress = 1;                            { I/O in progress }
  14.  
  15.         ipBadLapErr = -23000;                    { bad network configuration }
  16.         ipBadCnfgErr = -23001;                { bad IP configuration error }
  17.         ipNoCnfgErr = -23002;                    { missing IP or LAP configuration error }
  18.         ipLoadErr = -23003;                    { error in MacTCP load }
  19.         ipBadAddr = -23004;                    { error in getting address }
  20.         connectionClosing = -23005;            { connection is closing }
  21.         invalidLength = -23006;
  22.         connectionExists = -23007;            { request conflicts with existing connection }
  23.         connectionDoesntExist = -23008;        { connection does not exist }
  24.         insufficientResources = -23009;        { insufficient resources to perform request }
  25.         invalidStreamPtr = -23010;
  26.         streamAlreadyOpen = -23011;
  27.         connectionTerminated = -23012;
  28.         invalidBufPtr = -23013;
  29.         invalidRDS = -23014;
  30.         invalidWDS = -23014;
  31.         openFailed = -23015;
  32.         commandTimeout = -23016;
  33.         duplicateSocket = -23017;
  34.  
  35. { Error codes from internal IP functions }
  36.         ipDontFragErr = -23032;                { Packet too large to send w/o fragmenting }
  37.         ipDestDeadErr = -23033;                { destination not responding }
  38.         ipNoFragMemErr = -23036;            { no memory to send fragmented pkt }
  39.         ipRouteErr = -23037;                    { can't route packet off-net }
  40.  
  41.         nameSyntaxErr = -23041;
  42.         cacheFault = -23042;
  43.         noResultProc = -23043;
  44.         noNameServer = -23044;
  45.         authNameErr = -23045;
  46.         noAnsErr = -23046;
  47.         dnrErr = -23047;
  48.         outOfMemory = -23048;
  49.  
  50.     const
  51.         CTRUE = $FF;
  52.         CFALSE = $00;
  53.  
  54.     type
  55.         CBOOLEAN = signedByte;
  56.         ip_addr = longInt;
  57.         tcp_port = integer;
  58.         udp_port = integer;
  59.         StreamPtr = ptr;
  60.  
  61.     type
  62.         wdsType = record            { Write block for TCP driver. }
  63.                 size: integer;                { Number of bytes. }
  64.                 buffer: Ptr;                { Pointer to bytes. }
  65.                 term: integer;                { Zero for end of blocks. }
  66.             end;
  67.         wdsPtr = ^wdsType;
  68.  
  69.         hostInfo = record
  70.                 rtnCode: longInt;
  71.                 rtnHostName: str255;
  72.                 addrs: array[1..4] of longInt;
  73.             end;
  74.         hostInfoPtr = ^hostInfo;
  75.  
  76.     const { csCodes for the TCP driver: }
  77.         TCPcsGetMyIP = 15;
  78.         ipctlLAPStats = 19;
  79.         TCPcsCreate = 30;
  80.         TCPcsPassiveOpen = 31;
  81.         TCPcsActiveOpen = 32;
  82. {    TCPcsActOpenWithData = 33;}
  83.         TCPcsSend = 34;
  84.         TCPcsNoCopyRcv = 35;
  85.         TCPcsRcvBfrReturn = 36;
  86.         TCPcsRcv = 37;
  87.         TCPcsClose = 38;
  88.         TCPcsAbort = 39;
  89.         TCPcsStatus = 40;
  90.         TCPcsExtendedStat = 41;
  91.         TCPcsRelease = 42;
  92.         TCPcsGlobalInfo = 43;
  93.  
  94.         UDPcsCreate = 20;
  95.         UDPcsRead = 21;
  96.         UDPcsBfrReturn = 22;
  97.         UDPcsWrite = 23;
  98.         UDPcsRelease = 24;
  99.         UDPcsMaxMTUSize = 25;
  100.         UDPcsStatus = 26;
  101.         UDPcsMultiCreate = 27;
  102.         UDPcsMultiSend = 28;
  103.         UDPcsMultiRead = 29;
  104.         UDPcsCtlMax = 29;
  105.  
  106.     type
  107.         TCPEventCode = integer;
  108.     const
  109.         TEC_Closing = 1;
  110.         TEC_ULPTimeout = 2;
  111.         TEC_Terminate = 3;
  112.         TEC_DataArrival = 4;
  113.         TEC_Urgent = 5;
  114.         TEC_ICMPReceived = 6;
  115.         TEC_last = 32767;
  116.  
  117.     type
  118.         UDPEventCode = integer;
  119.     const
  120.         UDPDataArrival = 1;
  121.         UDPICMPReceived = 2;
  122.         lastUDPEvent = 32767;
  123.  
  124.     type
  125.         TCPTerminateReason = integer;
  126.     const {TCPTerminateReasons: }
  127.         TTR_RemoteAbort = 2;
  128.         TTR_NetworkFailure = 3;
  129.         TTR_SecPrecMismatch = 4;
  130.         TTR_ULPTimeoutTerminate = 5;
  131.         TTR_ULPAbort = 6;
  132.         TTR_ULPClose = 7;
  133.         TTR_ServiceError = 8;
  134.         TTR_last = 32767;
  135.  
  136.     type
  137.         TCPNotifyProc = procPtr;
  138. { procedure TCPNotifyProc(tcpStream:StreamPtr; event:TCPEventCode; userDataPtr:ptr; }
  139. {                                   terminReason:TCPTerminateReason; icmpMsg:ICMPReportPtr); }
  140.  
  141.     type
  142.         TCPIOCompletionProc = procPtr;
  143. { C procedure TCPIOCompletionProc(iopb:TCPControlBlockPtr); - WHY IS THIS A C PROC???? }
  144.  
  145.     type
  146.         UDPNotifyProc = procPtr;
  147. { procedure UDPProc(udpStream:StreamPtr ; eventCode:integer;userDataPtr:ptr; icmpMsg:ICMPReportPtr) }
  148.  
  149.     type
  150.         UDPIOCompletionProc = procPtr;
  151. {procedure UDPIOCompletionProc(iopb:UDPiopb Ptr) }
  152.  
  153.     type
  154.         UDPCreatePB = record { for create and release calls }
  155.                 rcvBuff: Ptr;
  156.                 rcvBuffLen: longInt;
  157.                 notifyProc: UDPNotifyProc;
  158.                 localport: integer;
  159.                 userDataPtr: ptr;
  160.                 endingPort: udp_port;
  161.             end;
  162.  
  163.     type
  164.         UDPSendPB = record
  165.                 reserved: integer;
  166.                 remoteIP: longInt;
  167.                 remotePort: udp_port;
  168.                 wds: wdsPtr;
  169.                 checkSum: signedByte;
  170.                 sendLength: integer;
  171.                 userDataPtr: ptr;
  172.                 localPort: udp_port;
  173.             end;
  174.  
  175.     type
  176.         UDPReceivePB = record
  177.                 timeOut: integer;
  178.                 remoteIP: longInt;
  179.                 remotePort: integer;
  180.                 rcvBuff: ptr;
  181.                 rcvBuffLen: integer;
  182.                 secondTimeStamp: integer;
  183.                 userDataPtr: ptr;
  184.                 destHost: ip_addr;
  185.                 destPort: udp_port;
  186.             end;
  187.  
  188.     type
  189.         UDPMTUPB = record
  190.                 mtuSize: integer;
  191.                 remoteIP: ip_addr;
  192.                 userDataPtr: ptr;
  193.             end;
  194.  
  195.     type
  196.         UDPControlBlock = record
  197.                 fill12: array[1..6] of integer;
  198.                 ioCompletion: UDPIOCompletionProc;
  199.                 ioResult: integer;
  200.                 ioNamePtr: stringPtr;
  201.                 ioVRefNum: integer;
  202.                 ioCRefNum: integer;
  203.                 csCode: integer;
  204.                 udpStream: streamPtr;
  205.                 case integer of
  206.                     UDPcsCreate: (
  207.                             create: UDPCreatePB
  208.                     );
  209.                     UDPcsWrite: (
  210.                             send: UDPSendPB
  211.                     );
  212.                     UDPcsRead: (
  213.                             receive: UDPReceivePB
  214.                     );
  215.                     UDPcsBfrReturn: (
  216.                             return: UDPReceivePB
  217.                     );
  218.                     UDPcsMaxMTUSize: (
  219.                             mtu: UDPMTUPB
  220.                     );
  221.             end;
  222.  
  223.     const { Validity Flags }
  224.         timeOutValue = $80;
  225.         timeOutAction = $40;
  226.         typeOfService = $20;
  227.         precedence = $10;
  228.  
  229.     const { TOSFlags }
  230.         lowDelay = $01;
  231.         throughPut = $02;
  232.         reliability = $04;
  233.  
  234.     type
  235.         TCPCreatePB = packed record
  236.                 rcvBuff: ptr;
  237.                 rcvBuffLen: longInt;
  238.                 notifyProc: TCPNotifyProc;
  239.                 userDataPtr: ptr;
  240.             end;
  241.  
  242.         TCPOpenPB = packed record
  243.                 ulpTimeoutValue: byte;
  244.                 ulpTimeoutAction: byte;
  245.                 validityFalgs: byte;
  246.                 commandTimeoutValue: byte;
  247.                 remoteHost: ip_addr;
  248.                 remotePort: tcp_port;
  249.                 localHost: ip_addr;
  250.                 localPort: tcp_port;
  251.                 tosFlags: byte;
  252.                 precedence: byte;
  253.                 dontFrag: CBOOLEAN;
  254.                 timeToLive: byte;
  255.                 security: byte;
  256.                 optionCnt: byte;
  257.                 options: array[0..39] of byte;
  258.                 userDataPtr: ptr;
  259.             end;
  260.  
  261.         TCPSendPB = packed record
  262.                 ulpTimeoutValue: byte;
  263.                 ulpTimeoutAction: byte;
  264.                 validityFalgs: byte;
  265.                 pushFalg: byte;
  266.                 urgentFlag: CBOOLEAN;
  267.                 wds: wdsptr;
  268.                 sendFree: longInt;
  269.                 sendLength: integer;
  270.                 userDataPtr: ptr;
  271.             end;
  272.  
  273.         TCPReceivePB = packed record
  274.                 commandTimeoutValue: byte;
  275.                 filler: byte;
  276.                 markFlag: CBOOLEAN;
  277.                 urgentFlag: CBOOLEAN;
  278.                 rcvBuff: ptr;
  279.                 rcvBuffLength: integer;
  280.                 rdsPtr: ptr;
  281.                 rdsLength: integer;
  282.                 secondTimeStanmp: integer;
  283.                 userDataPtr: ptr;
  284.             end;
  285.  
  286.         TCPClosePB = packed record
  287.                 ulpTimeoutValue: byte;
  288.                 ulpTimeoutAction: byte;
  289.                 validityFlags: byte;
  290.                 userDataPtrX: ptr;   { Thats mad!  Its not on a word boundary! Parhaps a documentation bug??? }
  291.             end;
  292.  
  293.         HistoBucket = packed record
  294.                 value: integer;
  295.                 counter: longInt;
  296.             end;
  297.  
  298.     const
  299.         NumOfHistoBuckets = 7;
  300.  
  301.     type
  302.         TCPConnectionStats = packed record
  303.                 dataPktsRcvd: longInt;
  304.                 dataPktsSent: longInt;
  305.                 dataPktsResent: longInt;
  306.                 bytesRcvd: longInt;
  307.                 bytesRcvdDup: longInt;
  308.                 bytesRcvdPastWindow: longInt;
  309.                 bytesSent: longInt;
  310.                 bytesResent: longInt;
  311.                 numHistoBuckets: integer;
  312.                 sentSizeHisto: array[1..NumOfHistoBuckets] of HistoBucket;
  313.                 lastRTT: integer;
  314.                 tmrRTT: integer;
  315.                 rttVariance: integer;
  316.                 tmrRTO: integer;
  317.                 sendTries: byte;
  318.                 sourchQuenchRcvd: byte;
  319.             end;
  320.         TCPConnectionStatsPtr = ^TCPConnectionStats;
  321.  
  322.         TCPStatusPB = packed record
  323.                 ulpTimeoutValue: byte;
  324.                 ulpTimeoutAction: byte;
  325.                 unused: longInt;
  326.                 remoteHost: ip_addr;
  327.                 remotePort: tcp_port;
  328.                 localHost: ip_addr;
  329.                 localPort: tcp_port;
  330.                 tosFlags: byte;
  331.                 precedence: byte;
  332.                 connectionState: byte;
  333.                 filler: byte;
  334.                 sendWindow: integer;
  335.                 rcvWindow: integer;
  336.                 amtUnackedData: integer;
  337.                 amtUnreadData: integer;
  338.                 securityLevelPtr: ptr;
  339.                 sendUnacked: longInt;
  340.                 sendNext: longInt;
  341.                 congestionWindow: longInt;
  342.                 rcvNext: longInt;
  343.                 srtt: longInt;
  344.                 lastRTT: longInt;
  345.                 sendMaxSegSize: longInt;
  346.                 connStatPtr: TCPConnectionStatsPtr;
  347.                 userDataPtr: ptr;
  348.             end;
  349.  
  350.         TCPAbortPB = packed record
  351.                 userDataPtr: ptr;
  352.             end;
  353.  
  354.         TCPParam = packed record
  355.                 tcpRtoA: longInt;
  356.                 tcpRtoMin: longInt;
  357.                 tcpRtoMax: longInt;
  358.                 tcpMaxSegSize: longInt;
  359.                 tcpMaxConn: longInt;
  360.                 tcpMacWindow: longInt;
  361.             end;
  362.         TCPParamPtr = ^TCPParam;
  363.  
  364.         TCPStats = packed record
  365.                 tcpConnAttempts: longInt;
  366.                 tcpConnOpened: longInt;
  367.                 tcpConnAccepted: longInt;
  368.                 tcpConnClosed: longInt;
  369.                 tcpConnAborted: longInt;
  370.                 tcpOctetsIn: longInt;
  371.                 tcpOctetsOut: longInt;
  372.                 tcpOctetsInDup: longInt;
  373.                 tcpOctetsRetrans: longInt;
  374.                 tcpInputPkts: longInt;
  375.                 tcpOutputPkts: longInt;
  376.                 tcpDupPkts: longInt;
  377.                 tcpRetransPkts: longInt;
  378.             end;
  379.         TCPStatsPtr = ^TCPStats;
  380.  
  381.         StreamPtrArray = array[1..1000] of StreamPtr;
  382.         StreamPtrArrayPtr = ^StreamPtrArray;
  383.  
  384.         TCPGlobalInfoPB = packed record
  385.                 tcpParamp: TCPParamPtr;
  386.                 tcpStatsp: TCPStatsPtr;
  387.                 tcpCDBTable: StreamPtrArrayPtr;
  388.                 userDataPtr: ptr;
  389.                 maxTCPConnections: integer;
  390.             end;
  391.  
  392.         TCPGetMyIPPB = packed record
  393.                 ourAddress: ip_addr;
  394.                 ourNetMask: longInt;
  395.             end;
  396.  
  397.         TCPControlBlock = record
  398.                 qLink: QElemPtr;
  399.                 qType: INTEGER;
  400.                 ioTrap: INTEGER;
  401.                 ioCmdAddr: Ptr;
  402.                 ioCompletion: TCPIOCompletionProc; {completion routine, or NIL if none}
  403.                 ioResult: OSErr; {result code}
  404.                 ioNamePtr: StringPtr;
  405.                 ioVRefNum: INTEGER;
  406.                 ioCRefNum: INTEGER; {device refnum}
  407.                 case csCode : integer of
  408.                     TCPcsGetMyIP: (
  409.                             getmyip: TCPGetMyIPPB;
  410.                     );
  411.                     0: (
  412.                             tcpStream: StreamPtr;
  413.                             case integer of
  414.                                 TCPcsCreate: (
  415.                                         create: TCPCreatePB
  416.                                 );
  417.                                 TCPcsActiveOpen, TCPcsPassiveOpen: (
  418.                                         open: TCPOpenPB;
  419.                                 );
  420.                                 TCPcsSend: (
  421.                                         send: TCPSendPB;
  422.                                 );
  423.                                 TCPcsNoCopyRcv, TCPcsRcvBfrReturn, TCPcsRcv: (
  424.                                         receive: TCPReceivePB;
  425.                                 );
  426.                                 TCPcsClose: (
  427.                                         close: TCPClosePB;
  428.                                 );
  429.                                 TCPcsAbort: (
  430.                                         abort: TCPAbortPB;
  431.                                 );
  432.                                 TCPcsStatus: (
  433.                                         status: TCPStatusPB;
  434.                                 );
  435.                                 TCPcsGlobalInfo: (
  436.                                         globalInfo: TCPGlobalInfoPB
  437.                                 );
  438.                     );
  439.             end;
  440.         TCPControlBlockPtr = ^TCPControlBlock;
  441.  
  442. implementation
  443.  
  444. end.